package com.zkyc.framework.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zkyc.framework.common.constant.NumberConstant;
import com.zkyc.framework.common.utils.WebsiteUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动填充时间
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("isShow", NumberConstant.NUMBER_1, metaObject);
        this.setFieldValByName("isDeleted", NumberConstant.NUMBER_0, metaObject);
        this.setFieldValByName("gmtCreated", new Date(), metaObject);
        this.setFieldValByName("gmtUpdated", new Date(), metaObject);
        this.setFieldValByName("clickDate", new Date(), metaObject);
        this.setFieldValByName("createDate", new Date(), metaObject);
        this.setFieldValByName("updateDate", new Date(), metaObject);
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtUpdated", new Date(), metaObject);
        this.setFieldValByName("updateDate", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}